class People{  
     name:string//属性
    constructor(name:string){ // 添加构造函数
        this.name = name
    }
   say():void{
       console.log(this.name+"说：大家好才是真的好")
   }
} 
new People("666").say()

function show(p:People):void{
    console.log("大圣哪吒姜子牙")
    p.say()
}
let p1 = new People("小明") 
p1.say()  
show(p1) 

let p2 = {
    name:"小红",
    say:function(){
        console.log(this.name+"说：好迪真好")
    }
}
p2.say() 
show(p2)


class Dog{//java写法
    //公共属性 可以在类的外面进行访问
    public age:number
    // 私有属性 只能在本类使用
    private sex:boolean
    // 受保护的属性 可以在本类和子类访问
    protected weigh:number

    // any类型 是任意类型
    constructor(name,sex,weigh){//这里没加就是any
        this.age = name
        this.sex = sex
        this.weigh = weigh
    }

    public eat():void{
        console.log(this.age,this.sex,this.weigh)
        this.drink()
        this.sleep()
    }

    private drink():void{
        console.log("drink")
    }
    protected sleep():void{
        console.log("sleep")
    }
}

let d1 = new Dog(10,true,100)
console.log(d1.age)
d1.eat()

